<!DOCTYPE html>
<html lang="zh_CN">
<head>
    <#include "../common/header.ftl">
    <script>
        $(function () {
            $('.dic').click(function () {
                var did = $(this).data("did");
                $("#parentId").val(did);
                $("#searchForm").submit();
            });
            $('#dictionary  li[data-did="${qo.parentId}"]' ).addClass('active');
        });
    </script>
</head>
<body>

<div class="container " style="margin-top: 20px">
    <#include "../common/top.ftl">
    <div class="row">
        <div class="col-sm-3">
            <#include "../common/menu.ftl">
        </div>
        <div class="col-sm-9">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">明细管理</h1>
                </div>
            </div>
            <div class="col-lg-4">
                <ul id="menu" class="list-group">
                    <li class="list-group-item">
                        <a href="javascript:">
                            <span>数据字典目录</span>
                        </a>
                        <ul class="in" id="dictionary">
                            <#list pageInfo.list as dic>
                                <li  class="dic" data-did="${dic.id}">
                                    <a href="javascript:">${dic.title}</a>
                                </li>
                            </#list>
                        </ul>
                    </li>
                </ul>
            </div>
            <!--高级查询--->
            <form class="form-inline" id="searchForm" action="/systemdictionaryItem/list.do" method="post">
                <input type="hidden" name="currentPage" id="currentPage" value="1">
                <input type="hidden" name="parentId" id="parentId" value="${qo.parentId}">
            </form>
            <div class="col-lg-8">
                <#if pageInfoItem??>
                    <a href="javascript:" class="btn btn-success inputBtn">
                        <span class="glyphicon glyphicon-plus"></span> 添加字典明细
                    </a>
                    <table class="table table-striped table-hover">
                        <tr>
                            <th>编号</th>
                            <th>明细标题</th>
                            <th>明细序列</th>
                            <th>操作</th>
                        </tr>
                        <#list pageInfoItem.list as entity>
                            <tr>
                                <td>${entity_index+1}</td>
                                <td>${entity.title}</td>
                                <td>${entity.sequence}</td>
                                <td>
                                    <a class="btn btn-info btn-xs inputBtn" href="javascript:"
                                       data-json='${entity.json}'>
                                        <span class="glyphicon glyphicon-pencil"></span>编辑
                                    </a>
                                    <a href="javascript:" data-url="/systemdictionaryItem/delete.do?id=${entity.id}"
                                       class="btn btn-danger btn-xs deleteBtn">
                                        <span class="glyphicon glyphicon-trash"></span>删除
                                    </a>
                                </td>
                            </tr>
                        </#list>
                    </table>
                    <div style="text-align: center;">
                        <#include "../common/page.ftl">
                    </div>
                </#if>
            </div>
        </div>
    </div>
</div>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title" id="myModalLabel">编辑</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/systemdictionaryItem/saveOrUpdate.do" method="post" id="editForm">
                    <input type="hidden" name="id">
                    <#--隐藏字典的id-->
                    <input type="hidden" name="parentId" value="${qo.parentId}">
                    <div class="form-group">
                        <label class="col-sm-3 control-label">明细标题：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="title" placeholder="请输入明细标题">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-3 control-label">明细序列：</label>
                        <div class="col-sm-6">
                            <input type="number" class="form-control" name="sequence" placeholder="请输入明细序列">
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary submitBtn">保存</button>
            </div>
        </div>
    </div>
</div>
<script>
    $(".inputBtn").click(function () {
        // 4步走,清空,取值,回显,显示
        // 1. 清空
        $('#myModal input').val('');
        // 2. 取值
        var obj = $(this).data('json');
        // 3. 回显
        if (obj) {
            $('#myModal input[name="id"]').val(obj.id);
            $('#myModal input[name="title"]').val(obj.title);
            $('#myModal input[name="sequence"]').val(obj.sequence);
        }
        $('#myModal input[name="parentId"]').val(${qo.parentId});
        // 4. 显示
        $('#myModal').modal('show');
    });
</script>
</body>
</html>